-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix the bug with scrolling in Virtualize component with scaled elements #64013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the Virtualize component where scroll calculations were incorrect when CSS scaling transforms were applied to parent elements. The issue occurred because the component used physical pixel measurements without accounting for scale factors.
- Adds scale factor detection and compensation logic to handle CSS scale, zoom, and transform properties
- Converts physical pixel measurements to logical pixels for accurate virtualization calculations
- Includes test coverage for the scaling scenario with a new E2E test
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
VirtualizationScale.razor | New test component demonstrating virtualization with CSS scale applied to body |
QuickGridVirtualizeComponent.razor | Fixes items provider to respect pagination parameters |
Index.razor | Adds new test component to navigation options |
VirtualizationTest.cs | Adds E2E test to verify virtualization works with scaling |
Virtualize.ts | Core fix - adds scale factor detection and applies compensation to scroll calculations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! The comments are mostly optional changes/questions.
src/Components/test/testassets/BasicTestApp/VirtualizationScale.razor
Outdated
Show resolved
Hide resolved
d83ab62
to
b3b3f28
Compare
Performance analysisI used
Average time increase: 11%. |
// Check for scale property (can have separate X/Y values) | ||
if (computedStyle.scale && computedStyle.scale !== 'none' && computedStyle.scale !== '1') { | ||
const parts = computedStyle.scale.split(' '); | ||
const scaleY = parts.length > 1 ? parseFloat(parts[1]) : parseFloat(parts[0]); | ||
scaleFactor *= scaleY; // Use vertical scale for vertical scrolling | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you only need to check computedStyle.transform
as that should be the reliable single source-of-truth for combined transforms because the computed transform contains the resolved transform that includes scale, rotate, skew, and translate.
Fix the bug with scrolling in Virtualize component with scaled elements
Description
This pull request improves the
Virtualize
component’s handling of CSS scaling and transforms, ensuring correct virtualization behavior when parent elements use scale, zoom, or transform properties. It also adds new test to verify these changes.The issue was caused by inconsistent scaling algorithm between JS and C#. JS operates on physical units, let's call it physical pixels - scaled pixel values. It used to send physical measurements to C#. C# operates on logical pixels, see e.g.
ItemSize
descriptionaspnetcore/src/Components/Web/src/Virtualization/Virtualize.cs
Line 91 in a54e8df
and it assumed the values received from JS are not scaled. This PR standardizes the sizes to support logical-pixels-based communication between JS and C#.
Alternatives:
Changes:
Virtualize.ts
to detect and correctly handle CSS scale, zoom, and transform properties on parent elements, adjusting scroll calculations so virtualization works accurately under scaling scenarios.CanScrollWhenAppliedScale
to verify that virtualization works when CSS scale is applied.Fixes #59354